package com.bruce.pattern.behavioral.memento;

import org.junit.Test;

/**
 * Created by bruce on 2018/11/10 21:44
 */
public class MainTest {

    @Test
    public void test1() {

        Article article = new Article();
        article.setContent("我是内容");
        article.setTitle("快乐开发");
        article.setImgs("imags");

        //保存Article
        ArticleMementoManager articleMementoManager = new ArticleMementoManager();
        ArticleMemento articleMemento = article.saveToMemento();
        articleMementoManager.add(articleMemento);

        System.out.println("修改前:" + article);
        //修改Article
        article.setImgs("Java logo");
        article.setTitle("Java设计模式");
        article.setContent("备忘录模式");
        System.out.println("修改后:" + article);

        //回退
        article.undoFromMemento(articleMementoManager.get());
        System.out.println("回退:" + article);


    }


}
